import Vue from 'vue';
import Router from 'vue-router';
//import store from "../store";

Vue.use(Router);

var router = new Router({  
	routes:[
        //主页
        { path: '/', redirect: '/AppBase' },
        { path: '/AppBase', name:"AppBase", component: ()=>import('../pages/base/AppBase.vue'), children:[
            { path: '/', redirect: '/MainPage' },
            { path: '/MainPage', name: 'MainPage', component: ()=>import('../pages/base/MainPage.vue') },
            { path: '/MyPage', name: 'MyPage', component: ()=>import('../pages/base/MyPage.vue') }
        ]},
        //消息界面
        { path: '/MessagePage', name: 'MessagePage', component: ()=>import('../components/MessagePage.vue') } ,
        { path: '/Version', name: 'Version', component: ()=>import('../pages/base/Version.vue') },
        //练习分组界面
        { path: '/Training/ClassView', name: 'TrainingClassView', component: ()=>import('../pages/training/ClassView.vue') }, 
        //练习题目界面       
        { path: '/Training/QuestionView', name: 'TrainingQuestionView', component: ()=>import('../pages/training/QuestionView.vue') },               
        //测试分组界面
        { path: '/Test/SetClass', name: 'TestSetClass', component: ()=>import('../pages/test/SetClass.vue') }, 
        { path: '/Test/SetNumber', name: 'SetNumber', component: ()=>import('../pages/test/SetNumber.vue') }, 
        { path: '/Test/TestView', name: 'TestView', component: ()=>import('../pages/test/TestView.vue') }
        //测试设置界面

        //测试题目界面
    ],
    scrollBehavior(to,from,savePosition){
        //滚动条定位
        if(savePosition && to.meta.keepAlive){
            return savePosition;
        }
        else{
            return {x:0,y:0}
        }
    },
})
/*
//劫持router
var dir=1;

const routerPush = router.push;
const routerReplace = router.replace;
const routerGo = router.go;
router.push=function push(lacation,onComplete,onAbort){
    dir = 1;
    routerPush.apply(router,[lacation,onComplete,onAbort]);
};
router.replace=function replace(lacation,onComplete,onAbort){
    this.dir = 0;
    routerReplace.apply(router,[lacation,onComplete,onAbort]);
};
router.go = function go(n){
    this.dir = n>0?1:-1;
    routerGo.apply(router,[n]);
};
router.afterEach((to,from)=>{
    if(dir===1){
        if(to.meta.keepAlive===true){
            //压入缓存
            //this.keepAlivePages.push(to.name);
            store.commit('pushKeepAlivePages', to.name)
        }
    }
    else if(dir===-1){
        if(from.meta.keepAlive===true){
            //弹出缓存
            //this.keepAlivePages.pop();
            store.commit('popKeepAlivePages')
        }
    }
    dir=-1;
})
*/

export default router;